package cn.edu.hunau.utils;

/**
 * R表示响应结果
 * @Author 苏佳
 * @Date 2022 10 23 16 18
 **/
public class R {
    //标识状态
    private Boolean flag;
    //code表示业务相关的状态码
    private Integer code;
    private String message;
    private Object data;

    public static R ok(){
        R r = new R();
        r.setCode(ResultCodeEnum.SUCCESS.getCode());
        r.setMessage(ResultCodeEnum.SUCCESS.getMessage());
        r.setFlag(ResultCodeEnum.SUCCESS.getFlag());
        return r;
    }

    public static R error(){
        R r = new R();
        r.setCode(ResultCodeEnum.UNKOWN_ERROR.getCode());
        r.setMessage(ResultCodeEnum.UNKOWN_ERROR.getMessage());
        r.setFlag(ResultCodeEnum.UNKOWN_ERROR.getFlag());
        return r;
    }

    public static R setResult(ResultCodeEnum resultCodeEnum){
        R r = new R();
        r.setCode(resultCodeEnum.getCode());
        r.setMessage(resultCodeEnum.getMessage());
        r.setFlag(resultCodeEnum.getFlag());
        return r;
    }

    public R message(String message){
        this.setMessage(message);
        return this;
    }

    public R code(Integer code){
        this.setCode(code);
        return this;
    }

    public R data(Object obj){
        this.setData(obj);
        return this;
    }


    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }


    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public boolean isFlag() {
        return flag;
    }

    public void setFlag(boolean flag) {
        this.flag = flag;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
